package com.jack.database_exp.controller;
import com.jack.database_exp.bean.Worker;
import com.jack.database_exp.mapper.WorkerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
@Controller
public class DemoController{
    @Autowired
    WorkerMapper workerMapper;
    @RequestMapping("/hello")
    public String hello(HttpServletRequest request, HttpServletResponse response, @RequestParam("WName") String WName, @RequestParam("WTel") String WTel){
        HttpSession session = request.getSession();
        boolean flag = false;
        List<Worker> workers = workerMapper.queryWorkers();
        for (Worker worker : workers){
            if(worker.getWName().equals(WName)&&worker.getWTel().equals(WTel)){
                flag = true;
                break;
            }
        }
        if(flag){
            session.setAttribute("loginUser",WName);
            session.setMaxInactiveInterval(60*60);
            return "redirect:/main";
        }else{
            request.setAttribute("msg","密码错误");
            return "forward:/index";
        }
    }
}